<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//前台默认控制器
class IndexController extends Controller{
	
    //前台首页
    public function index(){
    		//获得顶级分类,导航条
    		$cateModel =  new \Common\Model\Cate;
    		$data = $cateModel->where("pid=0")->get();
		View::with('topCate',$data);
		//首页最新3篇文章
		$arcModel = new \Common\Model\Arc;
		//Arc和category关联   'category_cid'='cid'  就是为了在文章数据中   添加分类数据   为下面做准备
		$arcData = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','DESC')->limit(7)->get();
		$arcData4 = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','DESC')->limit(6)->get();
		$arcData5 = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','ASC')->limit(6)->get();
		$arcData6 = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','ASC')->limit(4)->get();

		// p($arcData);
		     //实例中间表模型
		$arcTagModel = new \Common\Model\ArcTag;
		foreach ($arcData as $k => $v) {
			//获得每篇文章的标签，然后压入数组
			//中间表和标签表关联
			$data = $arcTagModel->join('tag','tag_tid','=','tid')->where("article_aid={$v['aid']}")->field('tid,tname')->get();
			$arcData[$k]['tag'] = $data;
		}
		View::with('arcData',$arcData);
		View::with('arcData4',$arcData4);
		View::with('arcData5',$arcData5);
		View::with('arcData6',$arcData6);





		//首页right分类列表***********
		$cateModel =  new \Common\Model\Cate;
    	$Catedata = $cateModel->get();
    		//实例化文章模型
    	$ArcModel = new \Common\model\Arc;
    	foreach ($Catedata as $k => $v) {
    		$Catedata[$k]['num'] = $ArcModel->where("category_cid={$v['cid']}")->count();
    	}
    	// p($Catedata);
    	View::with('Catedata',$Catedata);




		//首页right标签云
		$TagModel = new \Common\Model\Tag;
		$rightTag = $TagModel->get();
		View::with('rightTag',$rightTag);





		//首页尾部-友情链接
		$LinkModel = new \Common\Model\Link;
		$FootLink = $LinkModel->get();
		View::with('FootLink',$FootLink);




    		
    		View::make();
    }
	
	
//	public function code(){
//	   Code::num(C('webset.code_len'))->fontColor(C('webset.code_color'))->make();
//	}
	
}




